home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-07-04 | 2.2 KB | 75 lines | [TEXT/MMCC] |
- /*
- TrapUtils.c
-
- OS and Toolbox trap-related utility functions. Adapted from code in Inside Macintosh Volume VI, pages 3–8 to 3–9
-
- Created 17 Sep 1992 TrapAvailable and its static "herlper" functions
- Modified 01 Jul 1994 by Francis H Schiffer, 3rd - to use UPPs
-
- Copyright © 1992 by Paul M. Hoffman
- Send comments or suggestions to paul.hoffman@umich.edu -or- dragonsmith@umich.edu
-
- This source code may be freely used, altered, and distributed in any way as long as:
- 1. It is GIVEN away rather than sold (except as expressly permitted by the author)
- 2. This statement and the above copyright notice are left intact.
-
- */
-
- #include "TrapUtils.h"
- #include <Traps.h>
-
- static short NumToolboxTraps (void);
- static UniversalProcPtr AA6EAddress (void); /* fhs 1994 july 1 */
- static UniversalProcPtr UnimplementedTrapAddress (void); /* fhs 1994 july 1 */
- static TrapType GetTrapType (short trapWord);
-
-
- Boolean TrapAvailable (short theTrap)
- {
- TrapType type;
-
- type = GetTrapType (theTrap);
- if (type == ToolTrap) {
- theTrap &= 0x07FF;
- if (theTrap >= NumToolboxTraps ())
- return FALSE;
- }
- return (NGetTrapAddress (theTrap, type) != UnimplementedTrapAddress ());
- }
-
- static short NumToolboxTraps (void)
- {
- static short NUM_TBX_TRAPS = -1; // Initialize NUM_TBX_TRAPS to a nonsensical value
-
- if (NUM_TBX_TRAPS == -1)
- NUM_TBX_TRAPS = ((NGetTrapAddress (_InitGraf, ToolTrap) == AA6EAddress ()) ? 0x0200 : 0x0400);
-
- return NUM_TBX_TRAPS;
- }
-
- static UniversalProcPtr AA6EAddress (void)
- { /* fhs 1994 July 01 - to use UniversalProcPtrs */
- static UniversalProcPtr AA6E_ADDR = NULL; // Initialize _AA6E_ADDR to a nonsensical value
-
- if (AA6E_ADDR == NULL)
- AA6E_ADDR = NGetTrapAddress (0xAA6E, ToolTrap);
-
- return AA6E_ADDR;
- }
-
- static UniversalProcPtr UnimplementedTrapAddress (void)
- { /* fhs 1994 July 01 - to use UniversalProcPtrs */
- static UniversalProcPtr UNIMP_TRAP_ADDR = NULL; // // Initialize UNIMP_TRAP_ADDR to a nonsensical value
-
- if (UNIMP_TRAP_ADDR == NULL)
- UNIMP_TRAP_ADDR = NGetTrapAddress (_Unimplemented, ToolTrap);
-
- return UNIMP_TRAP_ADDR;
- }
-
- static TrapType GetTrapType (short trapWord)
- {
- return (trapWord & 0x0800) ? ToolTrap : OSTrap;
- }
-
-